"""
@Time : 2024/6/17 下午9:46
@Auth : AmirKD
@IDE : PyCharm
"""
from util import util
from tkinter import ttk
from GUI import Vo
import tkinter as tk


def Print_Project_Info(Project_Info, window):
    # 定义一个字符串用于存储想要输出显示的内容
    str_out = ""
    # 项目信息为空将返回
    if Project_Info is None:
        set("项目信息为空")
        return
    if len(Project_Info) == 0:
        set("无项目信息")
        return
    # # 项目信息不为空
    # if len(Project_Info) != 0:
    #     str_out += "项目信息如下：\n"
    #     # 显示信息标题
    #     str_out += ("{:^7}".format("项目序号") +
    #                 "{:^7}".format("项目名称") +
    #                 "{:^7}".format("项目内容") +
    #                 "{:^7}".format("项目创建时间") +
    #                 "{:^5}".format("项目截止时间") +
    #                 "{:^9}".format("项目完成进度") +
    #                 "\n")
    #     for i in range(0, len(Project_Info)):
    #         # 格式化字符串
    #         str_out += ("{:^7}".format(Project_Info[i].get("ID")) + ' ' * (
    #                     11 - util().Len_Str(Project_Info[i].get("ID"))) +
    #                     "{:^7}".format(Project_Info[i].get("Name")) + ' ' * (
    #                                 11 - util().Len_Str(Project_Info[i].get("Name"))) +
    #                     "{:^7}".format(Project_Info[i].get("project")) + ' ' * (
    #                                 13 - util().Len_Str(Project_Info[i].get("project"))) +
    #                     "{:^7}".format(Project_Info[i].get("creat_time")) + ' ' * (
    #                                 10 - util().Len_Str(Project_Info[i].get("creat_time"))) +
    #                     "{:^5}".format(Project_Info[i].get("finish_time")) + ' ' * (
    #                                 5 - util().Len_Str(Project_Info[i].get("finish_time"))) +
    #                     "{:^9}".format(Project_Info[i].get("progress")) + ' ' * (
    #                                 11 - util().Len_Str(Project_Info[i].get("progress"))) +
    #                     "\n")
    #     # 在主界面显示项目信息
    #     return str_out

    # 项目信息不为空
    if len(Project_Info) != 0:
        str_out += "项目信息如下："
        # 创建表格
        # tree = ttk.Treeview(Vo.vo('').Window_Show().window)
        tree = ttk.Treeview(window, columns=("项目序号", "项目名称", "项目内容", "项目创建时间", "项目截止时间", "项目完成进度"),
                            show="headings", displaycolumns="#all")
        # tree["columns"] = ("项目序号", "项目名称", "项目内容", "项目创建时间", "项目截止时间", "项目完成进度")

        # 设置列宽
        tree.column("项目序号", width=100)
        tree.column("项目名称", width=300)
        tree.column("项目内容", width=500)
        tree.column("项目创建时间", width=100)
        tree.column("项目截止时间", width=100)
        tree.column("项目完成进度", width=100)

        # 创建每一列数据的名称
        tree.heading("项目序号", text="项目序号", anchor='w')
        tree.heading("项目名称", text="项目名称", anchor='w')
        tree.heading("项目内容", text="项目内容", anchor='w')
        tree.heading("项目创建时间", text="项目创建时间", anchor='w')
        tree.heading("项目截止时间", text="项目截止时间", anchor='w')
        tree.heading("项目完成进度", text="项目完成进度", anchor='w')

        # 放入数据
        for i in range(0, len(Project_Info)):
            tree.insert("", 'end', values=(Project_Info[i].get("ID"), Project_Info[i].get("Name"),
                                           Project_Info[i].get("project"), Project_Info[i].get("creat_time"),
                                           Project_Info[i].get("finish_time"), Project_Info[i].get("progress")))

        # 创建表头
        result1 = tk.StringVar()
        result1.set(str_out)
        Show_result1 = tk.Label(window, fg="black", bg="white", font=("Microsoft YaHei", 12), bd='0', anchor='nw',
                               textvariable=result1)
        # Show_result.place(x="50", y="50")
        Show_result1.pack(side='top', fill='both')
        tree.pack(expand=1, fill='both')

        # 在主界面显示项目信息
        return
